<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>上牌信息</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <form id="prj_prd_lic_info_form">
            <div class="fieldset1 tabel_col clearFix">
                <div class="fieldBox col_50">
                    <div class="label">上牌时间</div>
                    <div class="field">
                        <c:if test="${detailFlag==true }">
                            <span id="licDtTxt">${licInfo.licDt}</span>
                        </c:if>
                        <c:if test="${detailFlag!=true }">
                            <input name="licDt" id="licDt" type="text" class="ui-datepicker" value="${licInfo.licDt}"
                                   validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </c:if>
                    </div>
                </div>
                <div class="fieldBox col_100" id="iscar">
                    <div class="label">上牌机构</div>
                    <div class="field">
                        <input name="licOrgNm" id="licOrgNm" type="text" class="ui-textbox"
                               value="${licInfo.licOrg.licOrgNm }" onFocus="selectLicOrg();" validate="{required:true}">
                        <input name="orgId" id="orgId" type="hidden" class="ui-textbox" value="${licInfo.licOrg.id }">

                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">车牌号</div>
                    <div class="field">
                        <input name="vehNo" id="vehNo" type="text" class="ui-textbox" value="${licInfo.vehNo}"
                               validate="{required:true}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">车架号</div>
                    <div class="field">
                        <c:if test="${empty id }">
                            <span>${vehVO.vin}</span>
                        </c:if>
                        <c:if test="${not empty id }">
                            <span>${licInfo.vin}</span>
                        </c:if>
                    </div>
                </div>
                <!-- 专车以租代购 -->
                <ui:normalSelect pgCd="prjPrdLicInfoAddPage" cmpCd="prjPrdLicInfoAddPageForm" cmpDtlCd="carOwner"
                                 orgCds="${orgCds}"></ui:normalSelect>
                <div class="fieldBox col_50" id="recNoDiv" style="display: none">
                    <div class="label">登记编号</div>
                    <div class="field">
                        <input name="recNo" id="recNo" type="text" class="ui-textbox" value="${recNo }">
                    </div>
                </div>

                <div class="fieldBox col_50" id="audStsCdDiv">
                    <div class="label">上牌状态</div>
                    <div class="field">
                        <select name="audStsCd" id="audStsCd" data-value=""  >
                            <c:if test="${licInfo.audStsCd==2}">
                                <option value="2" selected>已上牌</option>
                                <option value="0">未上牌</option>
                            </c:if>
                            <c:if test="${licInfo.audStsCd==0}">
                                <option value="2">已上牌</option>
                                <option value="0" selected>未上牌</option>
                            </c:if>
                        </select>
                    </div>
                </div>

                <div class="fieldBox col_50" id="recNoTextDiv" style="display: none">
                    <div class="label">登记编号</div>
                    <div class="field">
                        <a href="javascript:showMtgDetail()" class="link">
                            <span name="recNo" id="recNo">${recNo}</span>
                        </a>
                    </div>
                </div>

                <div class="fieldBox col_100">
                    <div class="label"> 备注</div>
                    <div class="field">
                        <textarea name="licRem" id="licRem" rows="4" class="ui-textarea l-textarea" style="width:80%"
                                  value="" validate="">${licInfo.licRem }</textarea>
                        <span class="requiredSymbol" isShow="iscar" style="display:none">*</span>
                    </div>
                </div>

                <%--<div class="fieldBox col_100" id="prjPrdGird" style="display: none">--%>
                    <%--<div class="sqPanel">--%>
                        <%--<div id="feePayGrid">--%>
                            <%--<div id="ligergrid_prj_prd" class="sq-grid"></div>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                <%--</div>--%>

                <div class="fieldBox col_50" style="display: none">
                    <div class="field">
                        <input name="licId" id="licId" type="text" value="${licInfo.id }">
                        <input name="dtlId" id="dtlId" type="text" value="${licInfo.dtlId }">
                    </div>
                </div>
            </div>
            <div class="btnsBox">
                <span id="prj_prd_lic_info_add_btn_id" class="sq-button sq-button-round" onclick="save();"><!-- <i class="sqBtnIco_10"></i> -->保存</span>
                <c:if test="${checkSp==1 }">
                    <span id="passSpId" class="sq-button sq-button-round" onclick="passSp(${id});">验证通过</span>
                </c:if>
            </div>
        </form>
    </div>
    <!-- -------------tiansainan------------------------- -->
    <div>
        <c:if test="${checkSp == 0 }">
        <span id="prj_prd_lic_info_add_btn_id1" class="sq-button sq-button-round" value="2"
              onclick="YanZ();">验证通过</span>
        <span id="prj_prd_lic_info_add_btn_id2" class="sq-button sq-button-round" value="0"
              onclick="NotYanZ();">验证不通过</span>
    </div>
    </c:if>
    <!-- -------------tiansainan------------------------- -->
</div>

<script type="text/javascript">
    var BuOrgCd = '${BuOrgCd}';
    var detailFlag = '${detailFlag}';
    var dtlId = '${dtlId}';
    var id = '${id}';
    var taskDefKey = "${taskDefKey}";//节点判断上牌
    var carOwnerVal = '${licInfo.carOwner}';
    var licDt = '${licInfo.licDt}';
    var checkSp = "${checkSp}";
    var grid = null;

    $(function () {

        initStyle();
        var ligerForm = liger.get("prj_prd_lic_info_form");
        $("#prj_prd_lic_info_form").ligerForm({
            validate: true
        });
        $("#prj_prd_lic_info_form").check_ligerFormEditor();
        /* --------------------------tsn------------------------------------  */
        if (detailFlag == "false") {//修改操作隐藏验证
            $("#prj_prd_lic_info_add_btn_id1").hide();
            $("#prj_prd_lic_info_add_btn_id2").hide();
        }
        if (detailFlag == "true" && checkSp == "") {
            $("#prj_prd_lic_info_add_btn_id1").hide();
            $("#prj_prd_lic_info_add_btn_id2").hide();
        }

        /* --------------------------tsn------------------------------------  */
        if (detailFlag == "true") {
            $("#fileDetail").hide();
            $("#prj_prd_lic_info_add_btn_id").hide();
            if ($("#licPlc")) {
                $("#licPlc").attr("readonly", "readonly");
            }
            if ($("#licOrg")) {
                $("#licOrg").attr("readonly", "readonly");
            }
            if ($("#carOwner")) {
                $("#carOwner").attr("readonly", "readonly");
            }
            if ($("#licRem")) {
                $("#licRem").attr("readonly", "readonly");
            }
            if ($("#vehNo")) {
                $("#vehNo").attr("readonly", "readonly");
            }
            $("#licOrgNm").removeAttr("onfocus");
            if (BuOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK) {
                $("#recNoTextDiv").show();
                $("#prjPrdGird").show();
            }
        }
        if (BuOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK && detailFlag != "true") {
            $("#recNoDiv").show();
            $("#prjPrdGird").show();
        }

        if ($("#carOwner")) {
            $("#carOwner").val(carOwnerVal);
        }
        setFormatDateValue();
        // initGrid();
    });


    //初始化列表
    function initGrid() {
        var params = {};
        params.dtlId = dtlId;
        $("#ligergrid_prj_prd").ligerGrid({
            url: '<%=path%>/project/prjprdlicinfo/initPrjPrdDtlList.do',
            method: 'get',
            parms: params,
            columns: [
                {display: '产品名称', name: 'prjPrdDtlVO.prdNm', minWidth: 80, align: 'left', enabledSort: true},
                {display: '产品型号', name: 'prjPrdDtlVO.prdMdl', minWidth: 80, align: 'left', enabledSort: true},
                {display: '挂靠公司', name: 'prjPrdDtlVO.lnkCompNm', minWidth: 100, align: 'left', enabledSort: true},
                {display: '供应商', name: 'splNm', minWidth: 150, align: 'left', enabledSort: true},
                {display: '发动机编号', name: 'prjPrdVehInfoVO.engMdl', minWidth: 100, enabledSort: true},
                {display: '车架号', name: 'prjPrdVehInfoVO.vin', minWidth: 80, align: 'left', enabledSort: true},
                {display: '地盘号', name: 'prjPrdVehInfoVO.chsCertNo', minWidth: 60, align: 'left', enabledSort: true},
                {display: '单价', name: 'guidePc', minWidth: 80, align: 'left', enabledSort: true},
                {
                    display: '合格证号', name: 'prjPrdVehInfoVO.certNo', minWidth: 80, align: 'left',
                    render: function (rowdata, rowindex, value, column) {
                        var id = rowdata.prjPrdVehInfoVO == null ? " " : rowdata.prjPrdVehInfoVO.id;

                        var h = '';
                        if (value) {
                            h += '<a  href="javascript:showVehDetail(';
                            h += "'" + rowdata.prjPrdVehInfoVO.id + "',";
                            h += "'" + rowdata.prjPrdDtlVO.id + "'";
                            h += ')">' + value + '</a>'
                        }
                        return h;
                    },
                    enabledSort: true
                },
                {display: '客户名称', name: 'cstNm', minWidth: 60, align: 'left', enabledSort: true},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            // height:'100%',
            heightDiff: -2,
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            rownumbers: true,
            enabledEdit: true,
            usePagerOnLessPagesize: true,
            usePager: false
        });
        grid = liger.get("grid");
    }

    function initStyle() {
        if (BuOrgCd == "00000005") {
            $("#iscar").hide();
            $("#licOrgNm").attr("validate", "");
            /* $("span[isShow='iscar']").show();
            $("#licRem").attr("validate","{required:true}"); */
        }
    }

    /* ------------tiansainan-------------------------*/
    //获取当前tab 的ID
    var currentTabid = top.mainApp.parentTab.getSelectedTabItemID()

    //验证通过
    function YanZ() {
//	alert(1);
        if (licDt) {
            var licDate = DateUtils.formatDate(new Date(licDt), DateUtils.YYYY_MM_DD);
        }
        var YZ = $("#prj_prd_lic_info_add_btn_id1").attr("value");
        //修改上牌验证状态
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                id: id,
                YZ: YZ,
                licDt: licDt
            },
            url: '<%=path%>/project/prjprdlicinfo/add.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var callback = GET_W2Wcallback();
                    if (callback) callback(true);
                    Remove_navTab(currentTabid);
                }
            }
        })

    }

    //验证不通过
    function NotYanZ() {
        if (licDt) {
            var licDate = DateUtils.formatDate(new Date(licDt), DateUtils.YYYY_MM_DD);
        }
        var YZ = $("#prj_prd_lic_info_add_btn_id2").attr("value");
        //修改上牌验证状态
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                id: id,
                YZ: YZ,
                licDt: licDt
            },
            url: '<%=path%>/project/prjprdlicinfo/add.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var callback = GET_W2Wcallback();
                    if (callback) callback(false);
                    Remove_navTab(currentTabid);
                }
            }
        });
    }

    /* ------------tiansainan-------------------------*/

    function passSp(_id) {
        if (StringUtils.isNotEmpty(_id)) {
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {
                    id: _id,
                    audStsCd: FlowConstant.FLOW_CHECK_STATE_PASS
                },
                url: '<%=path%>/capPay/flow/modifySpStatus.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if (isFlow == 1) {
                            console.log("执行Remove_navTab===上牌");
                            Remove_navTab();//关闭刷新前置tab页(YAOXIURONG-FLOW)
                        }
                        var TAB = top.mainApp.parentTab;
                        var currentTabid = TAB.getSelectedTabItemID();
                        var currFrameElement = top.$("#" + currentTabid).get(0);
                        var callback = currFrameElement.W2W.callback;
                        callback();
                        top.tab.removeTabItem(currentTabid);
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
    }

    //设置日期值
    function setFormatDateValue() {
        var licDt = '${licInfo.licDt}';
        if (licDt) {
            var licDate = DateUtils.formatDate(new Date(licDt), DateUtils.YYYY_MM_DD);
            $("#licDt").val(licDate);//
            $("#licDtTxt").text(licDate);
        }

    }

    function selectLicOrg() {
        if ('${detailFlag}' != true) {
            $.ligerDialog.open({
                title: '选择机构信息',
                height: 500,
                width: 850,
                url: '<%=path%>/project/prjprdlicorg/toListPage.do'
            });
        }
    }

    var isFlow = '${isFlow}';

    function save() {
        var ligerForm = liger.get("prj_prd_lic_info_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();
        // var fileParams = getUploadResultParams();//获取附件上传的信息
        // data["fileParams"] = JSON.stringify(fileParams);
        var url = '<%=path%>/project/prjprdlicinfo/add.do';
        var id = $("#licId").val();
        data["orgId"] = $("#orgId").val();
        data["id"] = id;
        data["dtlId"] = dtlId;
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $("#licId").val(msg.data);
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    if (isFlow == 1) {
                        console.log("执行Remove_navTab===上牌");
                        Remove_navTab();//关闭刷新前置tab页(YAOXIURONG-FLOW)
                    }
                    var TAB = top.mainApp.parentTab;
                    var currentTabid = TAB.getSelectedTabItemID();
                    var currFrameElement = top.$("#" + currentTabid).get(0);
                    var callback = currFrameElement.W2W.callback;
                    callback();
                    top.tab.removeTabItem(currentTabid);
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //抵押详情页面
    function showMtgDetail() {
        var id = dtlId;
        var detailFlag = true;
        Add_navTab('tab_prj_prd_veh_mtg_detail' + id, '抵押详情', '<%=path%>/project/prjprdmtg/toAddPage.do?detailFlag=' + detailFlag + '&&id=' + id + '&&dtlId=' + dtlId);
    }

    function showVehDetail(id, dtlId) {
        var detailFlag = true;
        Add_navTab('tab_prj_prd_veh_info_detail' + id, '合格证详情', '<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag=' + detailFlag + '&&id=' + id + '&&dtlId=' + dtlId);
    }
</script>
<div class="clearLine"></div>
</body>
</html>